export const tools = {
  //格式化金额
  fixMoneyHelper: function(s) {
    if (s === '' || s == null) {
      return '';
    } else {
      /* eslint-disable */
      s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(2) + '';
      var l = s
        .split('.')[0]
        .split('')
        .reverse(),
        r = s.split('.')[1];
      var t = '';
      for (let i = 0; i < l.length; i++) {
        t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? ',' : '');
      }
      t = t
        .split('')
        .reverse()
        .join('');
      if (t.substring(0, 2) == '-,') {
        t = t.replace(',', '');
      }
      return t + '.' + r;
    }
  },

  //去空格
  deletespce: function (v) {
    v = v+"";
    return v.replace(/\s+/g, "");
  },


  //防抖动函数
  debounce: function (fn, delay) {
    return function () {
      // 通过 ‘this’ 和 ‘arguments’ 获取函数的作用域和变量
      let context = this;
      let args = arguments;
      clearTimeout(tools.timer);
      tools.timer = setTimeout(function () {
        fn.apply(context, args);
      }, delay);
    };
  },
  timer: '',
};
